package hauwei.year2024.month3;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

public class legoTower {
    static int towerSum=0;
    static int top=0;
    static int index=-1;
    static List<Integer> stack = new ArrayList<>(1000);
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        String[] numbers = input.split("\\s+");
        for (String numStr : numbers) {
            int num = Integer.parseInt(numStr);
            towerAdd(num);
        }
        scanner.close();
        while (index>=0) {
            System.out.print(stack.get(index));
            index--;
            if(index>=0){
                System.out.print(" ");
            }
        }
    }
    public static void towerAdd(int num){
        //如果和最顶层一样
        boolean flag=true;
        int sum=0;
        for(int i=index;i>=0;i--){
            sum+=stack.get(i);
            if(sum==num){
                flag=false;
                index=i-1;
                towerAdd(2*num);
                break;
            }
            if(sum>num){
                break;
            }
        }
        if(flag){
            stack.add(++index,num);
        }
    }
}
